<template>
  <!-- 退瓶消单 -->
  <el-dialog
    v-if="visible"
    v-el-drag-dialog
    title="退瓶消单"
    :visible.sync="visible"
    width="800px"
    append-to-body
    @closed="reset"
  >
    <el-form ref="dataForm" class="form" :rules="rules" :model="temp" label-width="100px" label-position="right">
      <el-form-item label="收款人:" style="width: 50%;"><el-input v-model="temp.depReceiver" disabled /></el-form-item>
      <el-form-item label="收款方式:" style="width: 50%;"><el-input v-model="calcType" disabled /></el-form-item>
      <el-form-item label="押瓶机构:" style="width: 50%;"><el-input v-model="temp.ckOrgName" disabled /></el-form-item>
      <el-form-item label="退瓶机构:" prop="orgSNNo" style="width: 50%;">
        <el-tree-select
          v-model="temp.orgSNNo"
          :clearable="false"
          class="tree-select"
          :popover-width="360"
          :select-params="{
            clearable: true,
            placeholder: '请选择组织机构',
          }"
          :tree-params=" {
            'expand-on-click-node': false,
            'highlight-current': true,
            props:{
              value:'orgSNNo',
              label: 'orgName',
              disabled: 'disabled',
            },
            data: treeData
          }"
          @node-click="selectTreeChange"
        />
      </el-form-item>
      <el-form-item label="开始时间:" style="width: 50%;"><el-input v-model="startDt" disabled /></el-form-item>
      <el-form-item label="结束时间:" style="width: 50%;">
        <el-date-picker
          v-model="endDt"
          style="width: 100%;"
          type="date"
          format="yyyy-MM-dd"
          :clearable="false"
          placeholder="选择日期"
          :picker-options="endDtPickerOptions"
        />
      </el-form-item>
      <el-form-item label="审核时间:" style="width: 50%;"><el-input v-model="auditDt" disabled /></el-form-item>
      <el-form-item label="消单时间:" style="width: 50%;">
        <el-date-picker
          v-model="operateDt"
          style="width: 100%;"
          type="datetime"
          format="yyyy-MM-dd HH:mm"
          :clearable="false"
          placeholder="选择日期"
          :picker-options="pickerOptions"
        />
      </el-form-item>
      <div class="table-row">
        <el-table :data="depositDetails">
          <el-table-column label="当前可退">
            <el-table-column
              type="index"
              width="40"
            />
            <el-table-column
              prop="goodsName"
              label="规格型号"
              width="100"
            />
            <el-table-column
              prop="deposit"
              label="押金(元/个)"
              width="100"
            />
            <el-table-column
              prop="goodsCount"
              label="数量"
            />
          </el-table-column>
        </el-table>
        <el-table
          :data="depositDetails"
          style="margin-left: 10px;"
        >
          <el-table-column label="选取退瓶数量">
            <el-table-column
              type="index"
              width="40"
            />
            <el-table-column
              prop="goodsName"
              label="规格型号"
              width="100"
            />
            <el-table-column
              prop="goodsCountNew"
              label="数量"
            >
              <template slot-scope="scope">
                <el-select v-model="scope.row.goodsCountNew" @change="(value) => goodsCountNewChange(value, scope.$index)">
                  <el-option v-for="(item,index) in scope.row.optionList" :key="index" :label="item" :value="item" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column
              prop="totalDeposit"
              label="退还押金"
            />
          </el-table-column>
        </el-table>
      </div>
      <div style="display: flex; align-items: center; justify-content: space-between; width: 100%; margin-bottom: 30px;">
        <div style="color: red;">{{ '(开始时间至结束时间共计' + day + ')' }}</div>
        <!-- <el-link v-show="filterGoodsCountList.length > 0" type="primary" :underline="false" @click="openFreeRentDetail">免收租金明细</el-link> -->
      </div>
      <el-form-item label="总押金:" style="width: 50%;"><el-input-number v-model="temp.totalDeposit" :controls="false" :precision="2" disabled style="width: 100%;" /></el-form-item>
      <el-form-item label="总租金:" style="width: 50%;">
        <el-input-number v-model="params.totalRental" :disabled="isDisabled" :controls="false" placeholder="请输入" :max="shouldReturnMoney" :precision="2" style="width: 100%;" @change="totalRentalChange" />
      </el-form-item>
      <el-form-item label="应退金额:" style="width: 50%;"><el-input-number v-model="shouldReturnMoney" :controls="false" :precision="2" style="width: 100%;" disabled /></el-form-item>
      <el-form-item label="实退金额:" style="width: 50%;">
        <el-input-number v-model="params.accReturnDeposit" :controls="false" placeholder="请输入" :max="99999" :precision="2" style="width: 100%;" />
      </el-form-item>
      <div style=" margin-bottom: 30px; color: red;">特别提示:【消单时间】即为回瓶确认时间,如若对应机构启用了库存此时的【消单时间】将直接影响库存变化</div>
      <el-form-item label="退款方式:" style="width: 100%;" prop="radio">
        <el-radio v-if="temp.paymentMethod&&temp.paymentMethod!==1&&!isOverTime&&!isConfig" v-model="temp.radio" :label="temp.paymentMethod">原支付渠道({{ formatColumnMap(paymenFilList, 'value', temp.paymentMethod, 'desc') }})</el-radio>
        <el-radio v-model="temp.radio" :label="1">现金</el-radio>
      </el-form-item>
      <el-form-item label="备注:" prop="returnDepositRemark" style="width: 100%;">
        <el-input
          v-model="temp.returnDepositRemark"
          type="textarea"
          :rows="3"
          placeholder="请输入备注"
          :maxlength="200"
          show-word-limit
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="reset">
        关闭
      </el-button>
      <el-button :loading="$loadingPlugin.add || $loadingPlugin.edit" type="primary" @click="success">
        保存
      </el-button>
    </div>
    <backReason ref="backReason" />
    <turnOrderConfirm ref="turnOrderConfirm" />
    <el-dialog
      width="500px"
      title="提示"
      :visible.sync="innerVisible"
      append-to-body
      @close="innerClose"
    >
      <p class="innerTips"> <svg-icon class="innerIcon" icon-class="warningIcon" />该用户在企业已没有任何押金，是否销户?</p>
      <el-form ref="dataForm" label-position="right" label-width="80px">
        <el-form-item label="销户原因:" prop="remark">
          <el-input v-model="remark" type="textarea" :rows="2" maxlength="100" show-word-limit />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="innerClose">取 消</el-button>
        <el-button type="primary" @click="innerConfirm">确定</el-button>
      </div>
    </el-dialog>
    <!-- <free-rent-detail ref="freeRentDetail" /> -->
  </el-dialog>
</template>

<script>
  import moment from 'dayjs'
  import { formatColumnMap, parseTime } from '@/utils'
  import { queryCashPledgeInventory, queryCashPledgeDetail, customerCancle } from '@/api'
  import { mapGetters } from 'vuex'
  import backReason from './backReason'
  import turnOrderConfirm from './TurnOrderConfirm'
  // import freeRentDetail from './FreeRentDetail.vue'
  import dayjs from 'dayjs'

  export default {
    name: 'TurnOrder',
    components: { backReason, turnOrderConfirm },
    props: {
      calcTypeList: {
        type: Array,
        required: true
      },
      paymenFilList: {
        type: Array,
        required: true
      },
      treeData: {
        type: Array,
        required: true
      }
    },
    data() {
      return {
        visible: false,
        isDisabled: false,
        day: '',
        depositDetails: [],
        endDt: new Date(),
        operateDt: new Date(),
        params: {
          totalRental: 0,
          accReturnDeposit: undefined
        },
        shouldReturnMoney: 0,
        temp: {
          orgSNNo: '', // 所属机构orgSNNo
          radio: '',
          returnDepositRemark: ''
        },
        // 清单时间
        pickerOptions: { // 禁用当前之后的日期
          disabledDate(time) {
            return time.getTime() > Date.now()
          }
        },
        innerVisible: false,
        remark: '',
        depositInfo: {}
        // goodsCountList: []
      }
    },
    computed: {
      ...mapGetters([
        'corpSettingData',
        'userInfo'
      ]),
      rules() {
        let rules = {
          orgSNNo: [{ required: true, message: '请选择责任机构', trigger: 'change' }],
          radio: [{ required: true, message: '请选择退款方式', trigger: 'change' }]
        }
        // 晋江城市 备注选项必填
        if (this.userInfo.showRN === 58) {
          rules = {
            ...rules,
            returnDepositRemark: [{ required: true, message: '请输入备注', trigger: 'change' }]
          }
        }
        return rules
      },
      // 收款方式
      calcType: function() {
        return formatColumnMap(this.calcTypeList, 'value', this.temp.calcType, 'desc')
      },
      // 开始时间
      startDt: function() {
        return this.temp.beginDt && parseTime(this.temp.beginDt, '{y}-{m}-{d}')
      },
      // 审核时间
      auditDt: function() {
        return this.temp.auditDt && parseTime(this.temp.auditDt, '{y}-{m}-{d} {h}:{i}:{s}')
      },
      // 是否超过两个月
      isOverTime: function() {
        const s = dayjs(this.depositInfo.createTime)
        const e = dayjs(new Date())
        console.log(this.depositInfo.createTime, s, e, e.diff(s, 'month'))
        if (e.diff(s, 'month') > 2) {
          return true
        } else {
          return false
        }
      },
      // 勾选回执已回的押金单退款时，只支持退现金
      isConfig: function() {
        return !!(this.corpSettingData.sp6 >> 30 & 0x01)
      },
      // filterGoodsCountList() {
      //   const startYear = moment(this.startDt).year()
      //   const endYear = moment(this.endDt).year()
      //   return this.goodsCountList.filter(item => {
      //     return startYear <= item.signYear && item.signYear <= endYear && item.goodsCount >= this.corpSettingData.goodsCountFree
      //   })
      // },
      endDtPickerOptions() {
        if (this.startDt) {
          const _this = this
          return {
            disabledDate(time) {
              return time.getTime() < new Date(_this.startDt).getTime() - 8.64e7
            }
          }
        } else {
          return false
        }
      }
    },
    watch: {
      endDt: {
        handler(newName, oldName) {
          if (!this.visible) return
          if (moment(this.endDt).format('YYYY-MM-DD') < moment(this.temp.beginDt).format('YYYY-MM-DD')) {
            this.$message({
              type: 'error',
              message: '结束时间不能小于开始时间!'
            })
            return
          }
          // 处理开始时间和结束时间差
          // const numDt = (Date.parse(this.endDt) * 1) - (Date.parse(this.temp.beginDt) * 1)
          const numDt = Date.parse(moment(this.endDt).format('YYYY-MM-DD')) - Date.parse(moment(this.temp.beginDt).format('YYYY-MM-DD'))
          this.day = `${Math.floor(numDt / 60 / 60 / 24 / 1000)}天`
          if (this.temp.calcType === 3) {
            var monthDiff = (moment(this.endDt).format('YYYY') * 12 + moment(this.endDt).format('M') * 1) - (moment(this.temp.beginDt).format('YYYY') * 12 + moment(this.temp.beginDt).format('M') * 1) + 1
            this.day = monthDiff + '个自然月'
            if ((this.corpSettingData.sp1 >> 24 & 0x01) === 0x01) {
              // if (this.depositInfo.csmType === 1 && this.corpSettingData.goodsCountFree > 0) {
              //   const res1 = await querySignCountList({
              //     csmId: this.depositInfo.csmId,
              //     signTimeEnd: moment(this.endDt).format('YYYY-MM-DD') + ' 23:59:59'
              //   })
              //   this.goodsCountList = res1.data.map(item => ({
              //     signYear: item.signYear,
              //     goodsCount: item.goodsCount
              //   }))
              //   monthDiff = this.countMonthsWithYearsBelowThreshold(this.startDt, this.endDt)
              // }
              let totalRentalMoney = 0
              if (this.temp.totalTankRental) {
                totalRentalMoney = monthDiff * this.temp.totalTankRental
              } else totalRentalMoney = monthDiff * 0
              this.params.totalRental = totalRentalMoney
              if (this.temp.realTotalRental > 0 && totalRentalMoney > this.temp.realTotalRentalrealTotalRental) {
                this.params.totalRental = this.temp.realTotalRental
                this.$message.info('总租金已超上限,取上限值')
              }
              if (!totalRentalMoney || totalRentalMoney <= 0) {
                this.isDisabled = false // 总租金可以编辑
              }
              if (this.depositDetails) {
                // 处理总租金
                var rental = 0
                this.depositDetails.map(l => {
                  l.totalRental = l.rental * l.goodsCountNew
                  rental += l.totalRental
                })
                this.params.totalRental = `${monthDiff * (rental * 1)}`
              } else {
                this.params.totalRental = 0
              }
            }
          }
          if ((this.corpSettingData.sp1 >> 24 & 0x01) === 0x01 && this.temp.calcType === 3) {
            this.isDisabled = true
          } else {
            this.isDisabled = false
          }
        }
      }
    },
    methods: {
      formatColumnMap,
      // // 计算符合条件的月份数量
      // countMonthsWithYearsBelowThreshold(start, end) {
      //   // 获取起始和结束年份
      //   const startYear = moment(start).year()
      //   const endYear = moment(end).year()
      //   // 用于存储符合条件的月份数
      //   let monthCount = 0
      //   // 遍历数据，判断每年的购买数量
      //   this.goodsCountList.forEach(entry => {
      //     const { signYear, goodsCount } = entry
      //     // 判断年份是否在指定日期范围内，且购买数量小于阈值
      //     if (signYear >= startYear && signYear <= endYear && goodsCount < this.corpSettingData.goodsCountFree) {
      //       let yearStartMonth = 1
      //       let yearEndMonth = 12
      //       // 如果是开始年份，按指定的开始月份计算
      //       if (signYear === startYear) {
      //         yearStartMonth = moment(start).month() + 1 // 月份从0开始，所以加1
      //       }
      //       // 如果是结束年份，按指定的结束月份计算
      //       if (signYear === endYear) {
      //         yearEndMonth = moment(end).month() + 1
      //       }
      //       // 累加该年份符合条件的月份数
      //       monthCount += yearEndMonth - yearStartMonth + 1
      //     }
      //   })
      //   console.log('monthCount', monthCount)
      //   return monthCount // 返回符合条件的月份数量
      // },
      async open(temp) {
        // 初始化时间
        this.operateDt = new Date()
        // this.getWinData(temp.depositCode)
        // 请求接口
        const res = await queryCashPledgeDetail({
          depCode: temp.depositCode,
          depositId: temp.depositId,
          depStatus: temp.depStatus
        })
        this.depositDetails = res.data.depositDetails
        this.depositInfo = res.data
        this.params.depositCode = temp.depositCode
        this.depositDetails.forEach((item, index) => {
          item.totalRental = 0
          const optionList = [0]
          if (item.goodsCount) {
            for (let i = 1; i <= item.goodsCount; i++) {
              optionList.push(i)
            }
          }
          item.optionList = optionList
          this.$set(this.depositDetails[index], 'goodsCountNew', 0)
          this.$set(this.depositDetails[index], 'totalDeposit', 0)
        })
        // 处理总租金
        if (temp.calcType === 0) {
          this.params.totalRental = 0
        } else {
          if ((this.corpSettingData.sp1 >> 24 & 0x01) === 0x01 && temp.calcType === 3) {
            this.isDisabled = true
          } else {
            this.isDisabled = false
          }
        }
        this.temp = temp
        // 处理默认机构逻辑
        const f = this.isHaveOrg(this.treeData, this.temp.ckOrgSNNo)
        console.log('默认机构', f && f.orgName ? f.orgName : '无')
        if (f && f.orgSNNo) {
          this.temp.orgSNNo = temp.ckOrgSNNo
          this.params.orgSNNo = temp.ckOrgSNNo
          this.params.returnOrgId = temp.ckOrgId
          this.params.returnOrgName = temp.ckOrgName
        }

        // if (this.depositInfo.csmType === 1 && this.corpSettingData.goodsCountFree > 0) {
        //   const res1 = await querySignCountList({
        //     csmId: this.depositInfo.csmId,
        //     signTimeEnd: moment(this.endDt).format('YYYY-MM-DD') + ' 23:59:59'
        //   })
        //   this.goodsCountList = res1.data.map(item => ({
        //     signYear: item.signYear,
        //     goodsCount: item.goodsCount
        //   }))
        // }
        // 处理开始时间和结束时间差
        const numDt = Date.parse(moment(this.endDt).format('YYYY-MM-DD')) - Date.parse(moment(this.temp.beginDt).format('YYYY-MM-DD'))
        this.day = `${Math.floor(numDt / 60 / 60 / 24 / 1000)}天`
        if (temp.calcType === 3) {
          var monthDiff = (moment(this.endDt).format('YYYY') * 12 + moment(this.endDt).format('M') * 1) - (moment(this.temp.beginDt).format('YYYY') * 12 + moment(this.temp.beginDt).format('M') * 1) + 1
          this.day = monthDiff + '个自然月'
          if (res.data.depositDetails) {
            // 处理总租金
            var rental = ''
            res.data.depositDetails.map(l => {
              rental = (rental * 1) + (l.rental * 1)
            })
            // this.params.totalRental = `${((Math.floor(numDt / 30 / 60 / 60 / 24 / 1000) + 1) * 1) * (rental * 1)}`
          } else {
            // this.params.totalRental = 0
          }
        }
        // if (Number(this.params.totalRental) === 0) {
        //   this.params.totalRental = 0
        // }
        // this.params.accReturnDeposit = temp.totalDeposit
        if ((this.corpSettingData.sp1 >> 24 & 0x01) === 0x01 && temp.calcType === 3) {
          this.isDisabled = true
        } else {
          this.isDisabled = false
        }
        this.shouldReturnMoney = this.temp.totalDeposit
        this.params.accReturnDeposit = this.shouldReturnMoney
        console.log('this.temp.paymentMethod', this.temp.paymentMethod)
        this.$set(this.temp, 'radio', '')
        this.$set(this.temp, 'returnDepositRemark', '')
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
        })
      },
      isHaveOrg(val, searchKey) {
        for (let _i = 0; _i < val.length; _i++) {
          if (Number(val[_i].orgSNNo) === Number(searchKey)) {
            return val[_i]
          } else {
            if (val[_i].children && val[_i].children.length > 0) {
              const res = this.isHaveOrg(val[_i].children, searchKey)
              if (res) {
                return res
              }
            }
          }
        }
        return null
      },
      goodsCountNewChange(value, index) {
        this.$nextTick(() => {
          var monthDiff = (moment(this.endDt).format('YYYY') * 12 + moment(this.endDt).format('M') * 1) - (moment(this.temp.beginDt).format('YYYY') * 12 + moment(this.temp.beginDt).format('M') * 1) + 1
          // if (this.depositInfo.csmType === 1 && this.corpSettingData.goodsCountFree > 0) {
          //   monthDiff = this.countMonthsWithYearsBelowThreshold(this.startDt, this.endDt)
          // }
          this.depositDetails[index].totalDeposit = value * (this.depositDetails[index].deposit || 0)
          this.depositDetails[index].totalRental = value * (this.depositDetails[index].rental || 0) * monthDiff
          console.log(this.depositDetails[index])
          let money = 0
          let money1 = 0
          this.depositDetails.forEach((item) => {
            money += item.totalDeposit
            money1 += item.totalRental
          })
          console.log('money1', money1)
          this.params.totalRental = money1
          this.shouldReturnMoney = money
          this.params.accReturnDeposit = this.shouldReturnMoney - this.params.totalRental
          if (this.params.accReturnDeposit < 0) {
            this.params.accReturnDeposit = 0
          }
        })
      },
      // async getWinData(depositCode) {
      //   const res = queryDepositReturnWin({ depositCode })
      // },
      // 总租金变化
      totalRentalChange(value) {
        const newValue = this.params.totalRental
        const realTotalRental = this.temp.realTotalRental || 0
        if (realTotalRental > 0 && newValue > realTotalRental) {
          this.$message.info('总租金已超上限,取上限值')
          this.params.totalRental = realTotalRental
        }
        const money = this.temp.totalDeposit - newValue
        if (money > 0) {
          this.params.accReturnDeposit = money
        }
        this.params.accReturnDeposit = this.shouldReturnMoney - value
      },
      async confirmReceiptStatusChange() {
        return new Promise((resolve, reject) => {
          // 单据状态【已审核】且回执状态【回执待回】条件下展示
          if (this.temp.depStatus === 2 && this.temp.reStatus === 2) {
            this.$confirm(`消单后，回执状态变更为“无需回执”，是否确定消单？`, '提示', {
              type: 'warning'
            }).then(() => {
              resolve()
            }).catch(() => {
              reject()
            })
          } else {
            resolve()
          }
        })
      },
      success() {
        this.$refs.dataForm.validate(async(valid) => {
          if (!valid) return
          if (moment(this.endDt).format('YYYY-MM-DD') < moment(this.temp.beginDt).format('YYYY-MM-DD')) {
            this.$message({
              type: 'error',
              message: '结束时间不能小于开始时间!'
            })
            return
          }
          if (Date.parse(this.operateDt) > new Date()) {
            this.$message({
              type: 'error',
              message: '消单时间不能大于当前时间'
            })
            return
          }
          if (Date.parse(this.operateDt) < Date.parse(this.temp.auditDt)) {
            this.$message({
              type: 'error',
              message: '消单时间不能小于审核时间'
            })
            return
          } else {
            this.params.operateDt = this.operateDt
          }
          if (!this.params.totalRental && this.params.totalRental !== 0 || isNaN(this.params.totalRental)) {
            this.$message({
              type: 'error',
              message: '请输入总租金'
            })
            return
          }
          if (this.params.accReturnDeposit === null || this.params.accReturnDeposit === '') {
            this.$message({
              type: 'error',
              message: '请输入实退金额'
            })
            return
          }
          if (this.params.accReturnDeposit < 0) {
            this.$message({
              type: 'error',
              message: '请输入合法实退金额'
            })
            return
          }
          /**
           * 根据流程配置【退瓶消单确认客户是否退空瓶】勾选展示确认弹窗
           */
          if ((this.corpSettingData.sp6 >> 23 & 0x01) === 0x01) {
            const res = await this.$refs.turnOrderConfirm.open()
            if (res) {
              this.params.returnDepBottleType = res.returnDepBottleType
            } else {
              return
            }
          }

          if ((this.corpSettingData.sp6 >> 4 & 0x01) === 0x01 && this.temp.radio === 1) {
            if (this.params.accReturnDeposit * 1 > this.shouldReturnMoney * 1) {
              const reason = await this.$refs.backReason.open()
              if (reason) {
                this.params.refundReason = reason
              } else {
                return
              }
            }
          } else {
            if (this.params.accReturnDeposit * 1 > this.shouldReturnMoney * 1) {
              this.$message({
                type: 'error',
                message: '实退金额不能大于应退金额'
              })
              return
            }
          }

          if (this.temp.radio !== 1) {
            if (this.params.accReturnDeposit !== this.temp.totalDeposit) {
              this.$message({
                type: 'error',
                message: '实退金额与总押金不一致，无法使用原支付渠道退款!'
              })
              return
            }
          }
          let num = 0
          this.depositDetails.forEach((item) => {
            num += item.goodsCountNew
          })
          if (!num) {
            this.$message({
              type: 'error',
              message: '退瓶数量必须大于1'
            })
            return
          }
          await this.confirmReceiptStatusChange()
          this.$confirm(`退款方式确认选择${this.temp.radio !== 1 ? `原支付渠道(${formatColumnMap(this.paymenFilList, 'value', this.temp.paymentMethod, 'desc')})` : '现金'}吗？`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '重新选择',
            type: 'warning'
          }).then(async() => {
            const res = await queryCashPledgeInventory({
              csmId: this.depositInfo.csmId,
              returnOrgId: this.params.returnOrgId,
              returnOrgName: this.params.returnOrgName,
              returnOrgSNNo: this.params.orgSNNo,
              depositCode: this.params.depositCode,
              endDt: this.endDt,
              operateDt: this.params.operateDt,
              totalRental: this.params.totalRental || 0,
              accReturnDeposit: this.params.accReturnDeposit,
              returnPaymentMethod: this.temp.radio,
              checkRereturnType: this.temp.radio !== 1 ? 1 : '',
              depositDetails: this.depositDetails,
              refundReason: this.params.refundReason,
              returnDepBottleType: this.params.returnDepBottleType,
              returnDepositRemark: this.temp.returnDepositRemark
            })
            if (res) {
              if (res.data === 0) {
                this.$message({
                  type: 'success',
                  message: '操作成功!'
                })
                this.$emit('turnUpDataTable')
                this.visible = false
                this.reset()
              }
              if (res.data === 1) {
                this.innerVisible = true
              }
            }
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消'
            })
          })
        })
      },
      reset() {
        // 初始化时间
        this.endDt = new Date()
        this.day = ''
        this.params.totalRental = 0
        this.params.accReturnDeposit = undefined
        this.depositDetails = []
        this.depositInfo = {}
        this.remark = ''
        this.$nextTick(() => {
          this.$refs.dataForm.clearValidate()
          this.$refs['dataForm'].resetFields()
        })
        this.visible = false
      },
      // 选择所属机构
      selectTreeChange(value) {
        this.temp.orgSNNo = value.orgSNNo
        this.params.orgSNNo = value.orgSNNo
        this.params.returnOrgId = value.orgId
        this.params.returnOrgName = value.orgName
        this.$nextTick(() => {
          this.$refs.dataForm.clearValidate()
        })
      },
      async innerConfirm() {
        if (!this.remark) {
          this.$message.error('请填写销户原因！')
          return
        }
        const params = {
          csmId: this.depositInfo.csmId, invalidStr: this.remark
        }
        const res = await customerCancle(params)
        if (!res.data) {
          this.$message.success('销户成功')
          this.$emit('turnUpDataTable')
          this.visible = false
          this.innerVisible = false
          this.reset()
        } else {
          this.$message({
            dangerouslyUseHTMLString: true,
            type: 'warning',
            message: res.data
          })
        }
      },
      innerClose() {
        this.remark = ''
        this.innerVisible = false
        this.$emit('turnUpDataTable')
        this.visible = false
        this.innerVisible = false
        this.reset()
      }
      // openFreeRentDetail() {
      //   this.$refs.freeRentDetail.open({
      //     dataList: this.filterGoodsCountList
      //   })
      // }
    }
  }
</script>

<style lang='scss' scoped>
.form {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.table-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 15px;
}
.innerTips {
  margin-bottom: 10px;
}
</style>
